package com.xiaoxiong.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xiaoxiong.bean.BaseLeftRightData;
import com.xiaoxiong.text.R;

public class LeftRightListAdapter extends BaseAdapter {
	/**
	 * 上下文
	 */
	private Context context;
	/**
	 * 临时保存数据的
	 */
	private List<BaseLeftRightData> datas;
	/**
	 * 显示数据的item的布局
	 */
	private LinearLayout layout;

	public LeftRightListAdapter(Context context, List<BaseLeftRightData> datas) {
		super();
		this.context = context;
		this.datas = datas;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public BaseLeftRightData getItem(int arg0) {
		return datas.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		//设置布局文件
		LayoutInflater inflater = LayoutInflater.from(context);
		layout = (LinearLayout) inflater.inflate(R.layout.item_leftrightlayout, null);

		//找到显示数据的id
		TextView left = (TextView) layout.findViewById(R.id.leftdata);
		TextView right = (TextView) layout.findViewById(R.id.rightdata);
		
		//显示数据
		left.setText(datas.get(arg0).getLeftData());
		right.setText(datas.get(arg0).getRightData());
		
		return layout;
	}

}
